<template>
  <el-dialog title="导入"
             width="400px"
  :close-on-click-modal="false"
  :visible.sync="visible">
    <div style="text-align: center">
      <div style="width: 360px;display: inline-block;overflow: hidden">
        <span style="float: left">导入excel</span>
        <el-button style="float: right;color: #f56c6c" type="text" @click="export_template()">导出模板</el-button>
      </div>
    </div>
    <el-upload
      style="text-align: center"
      class="upload-demo"
      drag
      :action="uploadAction"
      :on-success="uploadSuccess"
      :show-file-list="false"
      multiple
    >
      <i class="el-icon-upload"></i>
      <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
      <!--<div class="el-upload__tip" slot="tip">只能上传excel文件</div>-->
    </el-upload>

  </el-dialog>
</template>
<script>
  export default {
    data() {
      return {
        visible: false,
        uploadAction:'',
        exportTemplate:''
      }
    },
    methods:{
      init(obj){
        this.uploadAction = obj.uploadAction
        this.exportTemplate = obj.exportTemplate
        this.visible = true
      },
      uploadSuccess(response){
        console.log(response)
        if(response.code == 0){
          this.$message({
            message: '操作成功',
            type: 'success',
            duration: 1500,
            onClose: () => {
              this.visible = false
              this.$message.success(response.msg)
              this.$emit('refreshDataList')
            }
          })
        }else{
          this.$message.error(response.msg)
        }
      },
      export_template () {
        window.open(this.exportTemplate)
      }
    }
  }
</script>
